

* generate list of street addresses to geocode


clear 

insheet using OrigData/census_SA1_match.csv, comma

	rename party_code account_number 
	rename sa1 SA1
	keep account_number SA1

save Data/census_SA1_match.dta, replace

use Data/Interval_sample_analysis_robust.dta, clear

	duplicates drop account_number, force

	drop _merge

merge m:1 account_number using Data/census_SA1_match.dta

	drop if _merge ==2

	keep if SA1==. 

	keep account_number 

merge 1:1 account_number using Data/address.dta

	drop if _merge ==2

	drop _merge 
merge 1:1 account_number using Data/location.dta

	drop if _merge==2

	keep account_number pcode address1 suburb street* _merge

	replace address1 = strupper(address1)
	replace suburb = strupper(suburb)

	replace streetname = address1 if streetname==""

	replace suburb = street_addr_2 if suburb==""

	keep account_number streetname suburb pcode

	replace suburb=proper(suburb)

merge m:1 suburb using Data/postcode_list.dta, update keepusing(pcode)

	drop if _merge ==2

	drop _merge 

	drop if streetname==""

	sort streetname

	gen temp = substr(streetname,1,2) 
	gen temp2 = substr(temp,2,.)

	replace streetname = substr(streetname,3,.) if temp2==" "

	drop temp temp2

save Data/missingSA1_accounts.dta, replace


	duplicates drop pcode suburb streetname, force
	drop account_number

	order streetname suburb pcode
export delimited using Data/missingSA1.csv, delim(",") replace



